Google analytics template

工作流概述

这是一个包含22个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "K3uf8aY8wipScEay",
  "meta": {
    "instanceId": "558d88703fb65b2d0e44613bc35916258b0f0bf983c5d4730c00c424b77ca36a",
    "templateCredsSetupCompleted": true
  },
  "name": "Google analytics template",
  "tags": [],
  "nodes": [
    {
      "id": "6a9fc442-d0a3-48be-8dff-94f8d9cd5cf1",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        460,
        460
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "484cbc41-f57d-4c3d-a458-e439d480d290",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        460,
        640
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "b1b66e9b-5fea-407b-9c1e-39bd2a9d4a90",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        460,
        100
      ],
      "parameters": {
        "width": 714.172987012987,
        "content": "## Send Google analytics to A.I. and save results to baserow

This workflow will check for country views, page engagement and google search console results. It will take this week's data and compare it to last week's data.

[You can read more about this workflow here](https://rumjahn.com/how-i-used-a-i-to-be-an-seo-expert-and-analyzed-my-google-analytics-data-in-n8n-and-make-com/)"
      },
      "typeVersion": 1
    },
    {
      "id": "adde29fc-ddb5-4b50-aa78-313ac9ede879",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        633.6540259740264,
        320
      ],
      "parameters": {
        "color": 4,
        "width": 2097.92831168831,
        "height": 342.6576623376624,
        "content": "## Property ID

1. Create your [Google Analytics Credentials](https://docs.n8n.io/integrations/builtin/credentials/google/oauth-single-service/?utm_source=n8n_app&utm_medium=credential_settings&utm_campaign=create_new_credentials_modal)
2. Enter your [property ID](https://developers.google.com/analytics/devguides/reporting/data/v1/property-id)."
      },
      "typeVersion": 1
    },
    {
      "id": "f2fb8535-e81e-4ca1-80df-ee68edba6386",
      "name": "Get Page Engagement Stats for this week",
      "type": "n8n-nodes-base.googleAnalytics",
      "position": [
        700,
        460
      ],
      "parameters": {
        "simple": false,
        "returnAll": true,
        "metricsGA4": {
          "metricValues": [
            {
              "name": "screenPageViews",
              "listName": "other"
            },
            {
              "name": "activeUsers",
              "listName": "other"
            },
            {
              "name": "screenPageViewsPerUser",
              "listName": "other"
            },
            {
              "name": "eventCount",
              "listName": "other"
            }
          ]
        },
        "propertyId": {
          "__rl": true,
          "mode": "id",
          "value": "460520224"
        },
        "dimensionsGA4": {
          "dimensionValues": [
            {
              "name": "unifiedScreenName",
              "listName": "other"
            }
          ]
        },
        "additionalFields": {}
      },
      "credentials": {
        "googleAnalyticsOAuth2": {
          "id": "b1GX8VBMKCUNweV1",
          "name": "Google Analytics account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "1d761425-cebf-4787-b286-b723a0851485",
      "name": "Get Page Engagement Stats for prior week",
      "type": "n8n-nodes-base.googleAnalytics",
      "position": [
        1060,
        460
      ],
      "parameters": {
        "simple": false,
        "endDate": "2024-10-23T00:00:00",
        "dateRange": "custom",
        "returnAll": true,
        "startDate": "={{$today.minus({days: 14})}}",
        "metricsGA4": {
          "metricValues": [
            {
              "name": "screenPageViews",
              "listName": "other"
            },
            {
              "name": "activeUsers",
              "listName": "other"
            },
            {
              "name": "screenPageViewsPerUser",
              "listName": "other"
            },
            {
              "name": "eventCount",
              "listName": "other"
            }
          ]
        },
        "propertyId": {
          "__rl": true,
          "mode": "id",
          "value": "460520224"
        },
        "dimensionsGA4": {
          "dimensionValues": [
            {
              "name": "unifiedScreenName",
              "listName": "other"
            }
          ]
        },
        "additionalFields": {}
      },
      "typeVersion": 2
    },
    {
      "id": "f8dac36b-9e8a-407f-b923-b4cea368f1bc",
      "name": "Parse data from Google Analytics",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        460
      ],
      "parameters": {
        "jsCode": "function transformToUrlString(items) {
 // Debug logging
 console.log('Input items:', JSON.stringify(items, null, 2));
 
 // Check if items is an array and has content
 if (!Array.isArray(items) || items.length === 0) {
 console.log('Items is not an array or is empty');
 throw new Error('Invalid data structure');
 }

 // Check if first item exists and has json property
 if (!items[0] || !items[0].json) {
 console.log('First item is missing or has no json property');
 throw new Error('Invalid data structure');
 }

 // Get the analytics data
 const analyticsData = items[0].json;
 
 // Check if analyticsData has rows
 if (!analyticsData || !Array.isArray(analyticsData.rows)) {
 console.log('Analytics data is missing or has no rows array');
 throw new Error('Invalid data structure');
 }
 
 // Map each row to a simplified object
 const simplified = analyticsData.rows.map(row => {
 if (!row.dimensionValues?.[0]?.value || !row.metricValues?.length) {
 console.log('Invalid row structure:', row);
 throw new Error('Invalid row structure');
 }
 
 return {
 page: row.dimensionValues[0].value,
 pageViews: parseInt(row.metricValues[0].value) || 0,
 activeUsers: parseInt(row.metricValues[1].value) || 0,
 viewsPerUser: parseFloat(row.metricValues[2].value) || 0,
 eventCount: parseInt(row.metricValues[3].value) || 0
 };
 });
 
 // Convert to JSON string and encode for URL
 return encodeURIComponent(JSON.stringify(simplified));
}

// Get input data and transform it
const urlString = transformToUrlString($input.all());

// Return the result
return { json: { urlString } };"
      },
      "typeVersion": 2
    },
    {
      "id": "ed880442-c92e-4347-b277-e8794aea6fbc",
      "name": "Parse GA data",
      "type": "n8n-nodes-base.code",
      "position": [
        1240,
        460
      ],
      "parameters": {
        "jsCode": "function transformToUrlString(items) {
 // Debug logging
 console.log('Input items:', JSON.stringify(items, null, 2));
 
 // Check if items is an array and has content
 if (!Array.isArray(items) || items.length === 0) {
 console.log('Items is not an array or is empty');
 throw new Error('Invalid data structure');
 }

 // Check if first item exists and has json property
 if (!items[0] || !items[0].json) {
 console.log('First item is missing or has no json property');
 throw new Error('Invalid data structure');
 }

 // Get the analytics data
 const analyticsData = items[0].json;
 
 // Check if analyticsData has rows
 if (!analyticsData || !Array.isArray(analyticsData.rows)) {
 console.log('Analytics data is missing or has no rows array');
 throw new Error('Invalid data structure');
 }
 
 // Map each row to a simplified object
 const simplified = analyticsData.rows.map(row => {
 if (!row.dimensionValues?.[0]?.value || !row.metricValues?.length) {
 console.log('Invalid row structure:', row);
 throw new Error('Invalid row structure');
 }
 
 return {
 page: row.dimensionValues[0].value,
 pageViews: parseInt(row.metricValues[0].value) || 0,
 activeUsers: parseInt(row.metricValues[1].value) || 0,
 viewsPerUser: parseFloat(row.metricValues[2].value) || 0,
 eventCount: parseInt(row.metricValues[3].value) || 0
 };
 });
 
 // Convert to JSON string and encode for URL
 return encodeURIComponent(JSON.stringify(simplified));
}

// Get input data and transform it
const urlString = transformToUrlString($input.all());

// Return the result
return { json: { urlString } };"
      },
      "typeVersion": 2
    },
    {
      "id": "46e092cc-af94-4e64-aa92-931c56345eff",
      "name": "Get Google Search Results for this week",
      "type": "n8n-nodes-base.googleAnalytics",
      "position": [
        1420,
        460
      ],
      "parameters": {
        "simple": false,
        "returnAll": true,
        "metricsGA4": {
          "metricValues": [
            {
              "name": "activeUsers",
              "listName": "other"
            },
            {
              "name": "engagedSessions",
              "listName": "other"
            },
            {
              "name": "engagementRate",
              "listName": "other"
            },
            {
              "name": "eventCount",
              "listName": "other"
            },
            {
              "name": "organicGoogleSearchAveragePosition",
              "listName": "other"
            },
            {
              "name": "organicGoogleSearchClickThroughRate",
              "listName": "other"
            },
            {
              "name": "organicGoogleSearchClicks",
              "listName": "other"
            },
            {
              "name": "organicGoogleSearchImpressions",
              "listName": "other"
            }
          ]
        },
        "propertyId": {
          "__rl": true,
          "mode": "id",
          "value": "460520224"
        },
        "dimensionsGA4": {
          "dimensionValues": [
            {
              "name": "landingPagePlusQueryString",
              "listName": "other"
            }
          ]
        },
        "additionalFields": {}
      },
      "credentials": {
        "googleAnalyticsOAuth2": {
          "id": "b1GX8VBMKCUNweV1",
          "name": "Google Analytics account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "709d0aaf-bd3d-4d83-9e66-b7df495855bd",
      "name": "Get Google Search Results for last week",
      "type": "n8n-nodes-base.googleAnalytics",
      "position": [
        1780,
        460
      ],
      "parameters": {
        "simple": false,
        "endDate": "={{$today.minus({days: 7})}}",
        "dateRange": "custom",
        "returnAll": true,
        "startDate": "={{$today.minus({days: 14})}}",
        "metricsGA4": {
          "metricValues": [
            {
              "name": "activeUsers",
              "listName": "other"
            },
            {
              "name": "engagedSessions",
              "listName": "other"
            },
            {
              "name": "engagementRate",
              "listName": "other"
            },
            {
              "name": "eventCount",
              "listName": "other"
            },
            {
              "name": "organicGoogleSearchAveragePosition",
              "listName": "other"
            },
            {
              "name": "organicGoogleSearchClickThroughRate",
              "listName": "other"
            },
            {
              "name": "organicGoogleSearchClicks",
              "listName": "other"
            },
            {
              "name": "organicGoogleSearchImpressions",
              "listName": "other"
            }
          ]
        },
        "propertyId": {
          "__rl": true,
          "mode": "id",
          "value": "460520224"
        },
        "dimensionsGA4": {
          "dimensionValues": [
            {
              "name": "landingPagePlusQueryString",
              "listName": "other"
            }
          ]
        },
        "additionalFields": {}
      },
      "credentials": {
        "googleAnalyticsOAuth2": {
          "id": "b1GX8VBMKCUNweV1",
          "name": "Google Analytics account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "7d3835d6-d1f5-4159-8e34-871871e63989",
      "name": "Parse Google Analytics Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1600,
        460
      ],
      "parameters": {
        "jsCode": "function transformToUrlString(items) {
 // In n8n, we need to check if items is an array and get the json property
 const data = items[0].json;
 
 if (!data || !data.rows) {
 console.log('No valid data found');
 return encodeURIComponent(JSON.stringify([]));
 }
 
 try {
 // Process each row
 const simplified = data.rows.map(row => ({
 page: row.dimensionValues[0].value,
 activeUsers: parseInt(row.metricValues[0].value) || 0,
 engagedSessions: parseInt(row.metricValues[1].value) || 0,
 engagementRate: parseFloat(row.metricValues[2].value) || 0,
 eventCount: parseInt(row.metricValues[3].value) || 0,
 avgPosition: parseFloat(row.metricValues[4].value) || 0,
 ctr: parseFloat(row.metricValues[5].value) || 0,
 clicks: parseInt(row.metricValues[6].value) || 0,
 impressions: parseInt(row.metricValues[7].value) || 0
 }));
 
 return encodeURIComponent(JSON.stringify(simplified));
 } catch (error) {
 console.log('Error processing data:', error);
 throw new Error('Invalid data structure');
 }
}

// Get the input data
const items = $input.all();

// Process the data
const result = transformToUrlString(items);

// Return the result
return { json: { urlString: result } };"
      },
      "typeVersion": 2
    },
    {
      "id": "c018fda4-a2e6-48f4-aabb-039c66374dc7",
      "name": "Parse Google Analytics Data1",
      "type": "n8n-nodes-base.code",
      "position": [
        1940,
        460
      ],
      "parameters": {
        "jsCode": "function transformToUrlString(items) {
 // In n8n, we need to check if items is an array and get the json property
 const data = items[0].json;
 
 if (!data || !data.rows) {
 console.log('No valid data found');
 return encodeURIComponent(JSON.stringify([]));
 }
 
 try {
 // Process each row
 const simplified = data.rows.map(row => ({
 page: row.dimensionValues[0].value,
 activeUsers: parseInt(row.metricValues[0].value) || 0,
 engagedSessions: parseInt(row.metricValues[1].value) || 0,
 engagementRate: parseFloat(row.metricValues[2].value) || 0,
 eventCount: parseInt(row.metricValues[3].value) || 0,
 avgPosition: parseFloat(row.metricValues[4].value) || 0,
 ctr: parseFloat(row.metricValues[5].value) || 0,
 clicks: parseInt(row.metricValues[6].value) || 0,
 impressions: parseInt(row.metricValues[7].value) || 0
 }));
 
 return encodeURIComponent(JSON.stringify(simplified));
 } catch (error) {
 console.log('Error processing data:', error);
 throw new Error('Invalid data structure');
 }
}

// Get the input data
const items = $input.all();

// Process the data
const result = transformToUrlString(items);

// Return the result
return { json: { urlString: result } };"
      },
      "typeVersion": 2
    },
    {
      "id": "d8f775cd-daf9-42de-a527-d932be46d945",
      "name": "Get Country views data for this week",
      "type": "n8n-nodes-base.googleAnalytics",
      "position": [
        2120,
        460
      ],
      "parameters": {
        "simple": false,
        "returnAll": true,
        "metricsGA4": {
          "metricValues": [
            {
              "name": "activeUsers",
              "listName": "other"
            },
            {
              "name": "newUsers",
              "listName": "other"
            },
            {
              "name": "engagementRate",
              "listName": "other"
            },
            {
              "name": "engagedSessions",
              "listName": "other"
            },
            {
              "name": "eventCount",
              "listName": "other"
            },
            {
              "listName": "other"
            },
            {
              "name": "sessions",
              "listName": "other"
            }
          ]
        },
        "propertyId": {
          "__rl": true,
          "mode": "id",
          "value": "460520224"
        },
        "dimensionsGA4": {
          "dimensionValues": [
            {
              "name": "country",
              "listName": "other"
            }
          ]
        },
        "additionalFields": {}
      },
      "credentials": {
        "googleAnalyticsOAuth2": {
          "id": "b1GX8VBMKCUNweV1",
          "name": "Google Analytics account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "7119e57c-cbf4-49a9-b0c9-1f3da1fd2af3",
      "name": "Get Country views data for last week",
      "type": "n8n-nodes-base.googleAnalytics",
      "position": [
        2440,
        460
      ],
      "parameters": {
        "simple": false,
        "endDate": "={{$today.minus({days: 7})}}",
        "dateRange": "custom",
        "returnAll": true,
        "startDate": "={{$today.minus({days: 14})}}",
        "metricsGA4": {
          "metricValues": [
            {
              "name": "activeUsers",
              "listName": "other"
            },
            {
              "name": "newUsers",
              "listName": "other"
            },
            {
              "name": "engagementRate",
              "listName": "other"
            },
            {
              "name": "engagedSessions",
              "listName": "other"
            },
            {
              "name": "eventCount",
              "listName": "other"
            },
            {
              "listName": "other"
            },
            {
              "name": "sessions",
              "listName": "other"
            }
          ]
        },
        "propertyId": {
          "__rl": true,
          "mode": "id",
          "value": "460520224"
        },
        "dimensionsGA4": {
          "dimensionValues": [
            {
              "name": "country",
              "listName": "other"
            }
          ]
        },
        "additionalFields": {}
      },
      "typeVersion": 2
    },
    {
      "id": "546d6cd2-6db6-4276-be35-abbe5a7e9b6a",
      "name": "Parse Google analytics data",
      "type": "n8n-nodes-base.code",
      "position": [
        2280,
        460
      ],
      "parameters": {
        "jsCode": "function transformToUrlString(items) {
 // In n8n, we need to check if items is an array and get the json property
 const data = items[0].json;
 
 if (!data || !data.rows) {
 console.log('No valid data found');
 return encodeURIComponent(JSON.stringify([]));
 }
 
 try {
 // Process each row
 const simplified = data.rows.map(row => ({
 country: row.dimensionValues[0].value,
 activeUsers: parseInt(row.metricValues[0].value) || 0,
 newUsers: parseInt(row.metricValues[1].value) || 0,
 engagementRate: parseFloat(row.metricValues[2].value) || 0,
 engagedSessions: parseInt(row.metricValues[3].value) || 0,
 eventCount: parseInt(row.metricValues[4].value) || 0,
 totalUsers: parseInt(row.metricValues[5].value) || 0,
 sessions: parseInt(row.metricValues[6].value) || 0
 }));
 
 return encodeURIComponent(JSON.stringify(simplified));
 } catch (error) {
 console.log('Error processing data:', error);
 throw new Error('Invalid data structure');
 }
}

// Get the input data
const items = $input.all();

// Process the data
const result = transformToUrlString(items);

// Return the result
return { json: { urlString: result } };"
      },
      "typeVersion": 2
    },
    {
      "id": "87cb137c-686d-49a5-8657-06ed0c5f5c27",
      "name": "Parse Google analytics data1",
      "type": "n8n-nodes-base.code",
      "position": [
        2600,
        460
      ],
      "parameters": {
        "jsCode": "function transformToUrlString(items) {
 // In n8n, we need to check if items is an array and get the json property
 const data = items[0].json;
 
 if (!data || !data.rows) {
 console.log('No valid data found');
 return encodeURIComponent(JSON.stringify([]));
 }
 
 try {
 // Process each row
 const simplified = data.rows.map(row => ({
 country: row.dimensionValues[0].value,
 activeUsers: parseInt(row.metricValues[0].value) || 0,
 newUsers: parseInt(row.metricValues[1].value) || 0,
 engagementRate: parseFloat(row.metricValues[2].value) || 0,
 engagedSessions: parseInt(row.metricValues[3].value) || 0,
 eventCount: parseInt(row.metricValues[4].value) || 0,
 totalUsers: parseInt(row.metricValues[5].value) || 0,
 sessions: parseInt(row.metricValues[6].value) || 0
 }));
 
 return encodeURIComponent(JSON.stringify(simplified));
 } catch (error) {
 console.log('Error processing data:', error);
 throw new Error('Invalid data structure');
 }
}

// Get the input data
const items = $input.all();

// Process the data
const result = transformToUrlString(items);

// Return the result
return { json: { urlString: result } };"
      },
      "typeVersion": 2
    },
    {
      "id": "06c4478d-a13a-4587-9f1f-451a68798a9f",
      "name": "Send page data to A.I.",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2760,
        460
      ],
      "parameters": {
        "url": "https://openrouter.ai/api/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={
 \"model\": \"meta-llama/llama-3.1-70b-instruct:free\",
 \"messages\": [
 {
 \"role\": \"user\",
 \"content\": \"You are an SEO expert. Compare the data from past 2 weeks, give me a table in markdown. Then give me 5 suggestions to improve my SEO. Output the data so that it works with markdown editors. Data from 2 weeks ago:{{ $json.urlString }} Data from last week: {{ $('Parse data from Google Analytics').item.json.urlString }}\"
 }
 ]
}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2,
      "alwaysOutputData": false
    },
    {
      "id": "4ad522b0-afe4-4eff-aa16-b86cc892ead8",
      "name": "Send page Search data to A.I.",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2920,
        460
      ],
      "parameters": {
        "url": "https://openrouter.ai/api/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={
 \"model\": \"meta-llama/llama-3.1-70b-instruct:free\",
 \"messages\": [
 {
 \"role\": \"user\",
 \"content\": \"You are an SEO expert. Compare the data from past 2 weeks, give me a table in markdown. Then give me 5 suggestions to improve my SEO. Output the data so that it works with markdown editors. Data from 2 weeks ago:{{ $('Parse Google Analytics Data1').item.json.urlString }} Data from last week:{{ $('Parse Google Analytics Data').item.json.urlString }}\"
 }
 ]
}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2,
      "alwaysOutputData": false
    },
    {
      "id": "07e1eebf-f16a-44c0-83b5-76bf65a3d3fc",
      "name": "Send country view data to A.I.",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3080,
        460
      ],
      "parameters": {
        "url": "https://openrouter.ai/api/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={
 \"model\": \"meta-llama/llama-3.1-70b-instruct:free\",
 \"messages\": [
 {
 \"role\": \"user\",
 \"content\": \"You are an SEO expert. Compare the data from past 2 weeks, give me a table in markdown. Then give me 5 suggestions to improve my SEO. Output the data so that it works with markdown editors. Data from 2 weeks ago:{{ $('Parse Google analytics data1').item.json.urlString }} Data from last week:{{ $('Parse Google analytics data').item.json.urlString }}\"
 }
 ]
}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2,
      "alwaysOutputData": false
    },
    {
      "id": "c4648ad8-2377-42a0-a431-931b53631c9d",
      "name": "Save A.I. output to Baserow",
      "type": "n8n-nodes-base.baserow",
      "position": [
        3240,
        460
      ],
      "parameters": {
        "tableId": 601,
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": 5833,
              "fieldValue": "Name of your blog"
            },
            {
              "fieldId": 5831,
              "fieldValue": "={{ $('Send page data to A.I.').item.json.choices[0].message.content }}"
            },
            {
              "fieldId": 5830,
              "fieldValue": "={{ $('Send page Search data to A.I.').item.json.choices[0].message.content }}"
            },
            {
              "fieldId": 5832,
              "fieldValue": "={{ $json.choices[0].message.content }}"
            },
            {
              "fieldId": 5829,
              "fieldValue": "={{ DateTime.now() }}"
            }
          ]
        },
        "operation": "create",
        "databaseId": 121
      },
      "typeVersion": 1
    },
    {
      "id": "e185c836-c12f-4452-92bd-0daaf33b653a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2760,
        180
      ],
      "parameters": {
        "color": 5,
        "width": 441.7412987012988,
        "height": 508.95792207792226,
        "content": "## Send data to A.I.

Fill in your Openrouter A.I. credentials. Use Header Auth.
- Username: Authorization
- Password: Bearer {insert your API key}

Remember to add a space after bearer. Also, feel free to modify the prompt to A.1."
      },
      "typeVersion": 1
    },
    {
      "id": "a1de2d16-d09e-4c74-8be1-f6bab8c34246",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3220,
        180
      ],
      "parameters": {
        "color": 6,
        "width": 331.32883116883124,
        "height": 474.88,
        "content": "## Send data to Baserow

Create a table first with the following columns:
- Name
- Country Views
- Page Views
- Search Report
- Blog 

Enter the name of your website under \"Blog\" field."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ac4b5eac-1c84-49ce-9ff7-794f857265b4",
  "connections": {
    "Parse GA data": {
      "main": [
        [
          {
            "node": "Get Google Search Results for this week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Page Engagement Stats for this week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send page data to A.I.": {
      "main": [
        [
          {
            "node": "Send page Search data to A.I.",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Google Analytics Data": {
      "main": [
        [
          {
            "node": "Get Google Search Results for last week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Google analytics data": {
      "main": [
        [
          {
            "node": "Get Country views data for last week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Google Analytics Data1": {
      "main": [
        [
          {
            "node": "Get Country views data for this week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Google analytics data1": {
      "main": [
        [
          {
            "node": "Send page data to A.I.",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send page Search data to A.I.": {
      "main": [
        [
          {
            "node": "Send country view data to A.I.",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send country view data to A.I.": {
      "main": [
        [
          {
            "node": "Save A.I. output to Baserow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse data from Google Analytics": {
      "main": [
        [
          {
            "node": "Get Page Engagement Stats for prior week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Get Page Engagement Stats for this week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Country views data for last week": {
      "main": [
        [
          {
            "node": "Parse Google analytics data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Country views data for this week": {
      "main": [
        [
          {
            "node": "Parse Google analytics data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Google Search Results for last week": {
      "main": [
        [
          {
            "node": "Parse Google Analytics Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Google Search Results for this week": {
      "main": [
        [
          {
            "node": "Parse Google Analytics Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Page Engagement Stats for this week": {
      "main": [
        [
          {
            "node": "Parse data from Google Analytics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Page Engagement Stats for prior week": {
      "main": [
        [
          {
            "node": "Parse GA data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Scheduletrigger
  • Manualtrigger
  • Stickynote
  • Googleanalytics
  • Code

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作